package com.vooda.controller;

import com.vooda.dto.bo.UserBo;
import com.vooda.dto.vo.BaseResult;
import com.vooda.dto.vo.UserVo;
import com.vooda.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author KennyDavid
 */


@Api(description = "用户中心")
@RestController
@RequestMapping("/user")
@Scope("prototype")
@Validated
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "登录，写入用户信息")
    @PostMapping("/login")
    public BaseResult<UserVo> login(@ApiParam(value = "用户表单") @RequestBody @Validated({UserBo.Post.class}) UserBo userBo, BindingResult bindingResult) {
        return userService.login(userBo);
    }

    @ApiOperation(value = "扫码成为收银员")
    @PutMapping("/auth/beCashier")
    public BaseResult beCashier() {
        return userService.beCashier(getUserId());
    }

    @ApiOperation(value = "获取手机号")
    @GetMapping("/auth/userPhone")
    public BaseResult userPhone(@ApiParam(value = "iv") @RequestParam String iv, @ApiParam(value = "encryptedData") @RequestParam String encryptedData) {
        return userService.userPhone(getUserId(), iv, encryptedData);
    }
}
